package secondStage.part3.泛型.可变参数个数运用;

/**
 * @ClassName: [GenericDemo6]
 * @Description: 可变参数：多个数据求和
 * @Author: [黄劲松]
 * @CreateDate: [2021-04-03]
 * @Version: [v1.0]
 */
/*4.6可变参数
  可变参数又称参数个数可变，用作方法的形参出现，那么方法参数个数就是可变的了
  格式:修饰符返回值类型方法名(数据类型...变量名){}
  范例: public static int sum(int...a) { }*/
public class GenericDemo6 {
    public static void main(String[] args) {
        System.out.println(sum(12, 13));
        System.out.println(sum(12, 13, 14));
        System.out.println(sum(12, 13, 14, 55));
        System.out.println(sum(12, 13, 14, 55, 100));
    }

    private static int sum(int b, int... a) {
        int sum = 0;
        for (int i : a) {
            sum += i;
        }
        return sum + b;
    }
}
